﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;
using System.Net;

namespace Ewts.BaseData
{
    public partial class CustomerAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["UserInfo"] != null)
                {
                    User curUser = new DataLib.Accounts.Bus.User();
                    curUser = (User)Session["UserInfo"];

                   
                }
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = ForEstimat();
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            else if (errorcode.InnerHtml != "")
            {
                MessageBox.Show(this, errorcode.InnerHtml);
                return;
            }

            string companyname = this.txtcompanyname.Text;
            string shortname = this.txtshortname.Text;
            string customercode = this.txtcustomercode.Value;
            string city = this.txtcity.Text;
            string settlement = this.txtsettlement.Text;
            string postcode = this.txtpostcode.Text;
            string linkman = this.txtlinkman.Text;
            string linkman2 = this.txtlinkman2.Text;
            string phone = this.txtphone.Text;
            string phone2 = this.txtphone2.Text;
            string Email = this.txtEmail.Text;
            string Email2 = this.txtEmail2.Text;
            string BankName = this.txtBankName.Text;
            string BankAccount = this.txtBankAccount.Text;
            string BankCode = this.txtBankCode.Text;
            string PutOnRecord = this.txtPutOnRecord.Text;
            string BankAddress = this.txtBankAddress.Text;
            //string SaleMan = dropSaleMan.SelectedValue;
            //string SaleMan = "";


            DataLib.Model.Cumtomer model = new DataLib.Model.Cumtomer();
            model.companyname = companyname;
            model.shortname = shortname;
            model.customercode = customercode;
            model.city = city;
            model.settlement = settlement;
            model.postcode = postcode;
            model.linkman = linkman;
            model.State = txtState.Text;
            model.province = txtProvince.Text;
            model.linkman2 = linkman2;
            model.phone = phone;
            model.phone2 = phone2;
            model.Email = Email;
            model.Email2 = Email2;
            model.BankName = BankName;
            model.BankAccount = BankAccount;
            model.BankCode = BankCode;
            model.PutOnRecord = PutOnRecord;
            model.BankAddress = BankAddress;
            //model.SaleMan = SaleMan;
            model.SaleMan = "";

            DataLib.BLL.Cumtomer bll = new DataLib.BLL.Cumtomer();
            bll.Add(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "CustomerAdd.aspx");

        }

        /// <summary>
        /// 判断输入的内容
        /// </summary>
        /// <returns>错误信息</returns>
        protected string ForEstimat()
        {
            string strErr = "";
            if(txtcompanyname.Text.Trim().Length ==0 )
            {
                strErr += "客户名称不能为空！\\n";
            }
            if (txtcustomercode.Value.Trim().Length == 0)
            {
                strErr += "客户编码不能为空！\\n";
            }
            return strErr;
        }

        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("CustomerList.aspx");
        }
    }
}
